/*
package com.xxgc.vfc.gateway.filter.overall;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.nio.charset.StandardCharsets;
import java.util.List;

*/
/**
 * @Author:sjy
 * @Date :2023/10/31 - 10 - 31 - 17:00
 * 全局身份过滤器
 * 自己的名称 + Global + Filter
 *//*

@Component
public class AuthGlobalFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        HttpHeaders headers = request.getHeaders();
        List<String> token = headers.get("token");
        //判断token是否为空
        if(!ObjectUtil.isNull(token)){
            System.out.println("没有登录");
            ServerHttpResponse response = exchange.getResponse();
            //加个响应头 中文乱码
            HttpHeaders responseHeaders = response.getHeaders();
            responseHeaders.setContentType(MediaType.APPLICATION_JSON);

            //返回401
            response.setStatusCode(HttpStatus.UNAUTHORIZED);
            String json = "{\"msg\":\"请求失败，请先登录\"}";
            byte[] bytes = json.getBytes(StandardCharsets.UTF_8);
            DataBuffer wrap = response.bufferFactory().wrap(bytes);
            return response.writeWith(Mono.just(wrap));
        }
        //放行
        return chain.filter(exchange);
    }
}
*/
